<%--                                                                       --%>
<%-- Copyright (c) 2004 BroadVision, Inc.  All rights reserved.            --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>

<script language="JavaScript">
  
  function doCancelAction(myform) {
    var ok = true;
    //if (checkAnyChange(myform) == true) {
    //  ok = confirm('<bean-el:message key="confirmCancel" bundle="ep.messages"/>');
    //}
    if (ok && myform != null) {
      if (<c:out value='${epBlockEditForm.map.id}'/> == 0) {
        myform.action = '<c:url value="/ep/blockList.do"/>';
      }
      else {
        myform.action = '<c:url value="/ep/blockView.do"/>';
      }
      myform.submit();
    }
  }

  function doResetAction(myform) {
    if (checkAnyChange(myform) == true) {
      myform.reset();
    }
  }
  
  function checkAnyChange(myform) {
    trimTextFields(myform);
    if (myform.name.value != myform.name.defaultValue) {
      return true;
    }
    if (myform.displayTemplateId.value != <c:out value="${epBlockEditForm.map.displayTemplateId}"/> &&
      (myform.blockId.value != 0 || myform.displayTemplateId.selectedIndex != 0)) {
      return true;
    }
    if (myform.description.value != myform.description.defaultValue) {
      return true;
    }
    if ('<c:out value="${epBlockEditForm.map.isSearchBlock}"/>' == 'false' && 
      '<c:out value="${epBlockEditForm.map.isNavigationBlock}"/>' == 'false') {
      var blockType = '<c:out value="${epBlockEditForm.map.blockType}"/>';
      if (myform.blockType[0].checked == true && blockType != '0') {
        return true;
      }
      if (myform.blockType[1].checked == true && blockType != '1') {
        return true;
      }
      if (myform.blockType[2].checked == true && blockType != '2') {
        return true;
      }
      var blockHeightType = '<c:out value="${epBlockEditForm.map.blockHeightType}"/>';
      if (myform.blockHeightType[0].checked == true && blockHeightType == '0') {
        if (myform.blockHeight.value != '<c:out value="${epBlockEditForm.map.blockHeight}"/>') {
          return true;
        }
      }
      if (myform.blockHeightType[0].checked == true && blockHeightType != '0') {
        return true;
      }
      if (myform.blockHeightType[1].checked == true && blockHeightType != '1') {
        return true;
      }
    }
    return false;
  }

  function trimTextFields(myform) {
    var theName = myform.name.value;
    myform.name.value = theName.stringTrim();
    var theDescription = myform.description.value;
    myform.description.value = theDescription.stringTrim();
  }

  function doValidation(myform) {
    trimTextFields(myform);
    if (validateBlock(myform) == false) {
      return false;
    }
    var displayTemplateId = myform.displayTemplateId;
    if (displayTemplateId.value <= 0) {
      alert('<bean-el:message key="ep.block.error.invalidDisplayTemplate" bundle="ep.messages"/>');
      myform.displayTemplateId.focus();
      return false;
    }
    return true;
  }
  
</script>

<% 
  java.util.HashMap map = new java.util.HashMap();
  String ptOid = request.getParameter("pageTypeId"); 
  if (ptOid != null && ptOid.length() > 0) {
    map.put("pageTypeId", ptOid);
  }
  else {
    map.put("pageTypeId", "-1");
  }
  pageContext.setAttribute("pagetabParam", map, PageContext.PAGE_SCOPE);
%>

<html-el:javascript formName="/ep/blockSave" method="validateBlock"/>
<html-el:form action="/ep/blockSave.do" focus="name" onsubmit="return doValidation(epBlockEditForm);">
<input type="hidden" name="pageTypeId" value="<c:out value='${epPageTypeView.map.id}'/>"/>
<input type="hidden" name="blockId" value="<c:out value='${epBlockEditForm.map.id}'/>"/>
<html-el:hidden property="id"/>
<html-el:hidden property="blockHeightType"/>
<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle">
<c:choose>
  <c:when test="${epBlockEditForm.map.id == 0}">
        <bean-el:message key="ep.block.create.page.title" arg0="${epPageTypeView.map.name}" bundle="ep.messages"/>
  </c:when>
  <c:otherwise>
        <bean-el:message key="ep.block.edit.page.title" arg0="${epBlockView.map.name}" arg1="${epPageTypeView.map.name}" bundle="ep.messages"/>
  </c:otherwise>
</c:choose> 
      </div>
      <div class="errorMessage"><html-el:errors bundle="ep.messages"/></div>
      <%@ include file="/mc/common/pagetab.jsp" %>
      <div class="pageSubtitle">
        <span class="left">
          <bean-el:message key="ep.block.information" bundle="ep.messages"/>
        </span>
        <span class="right">&nbsp;</span>
      </div> 
      <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
        <tr> 
          <td class="label" width="30%">
            <bean-el:message key="ep.block.name" bundle="ep.messages"/>:*
          </td>
          <td class="labelField" width="70%">
<c:choose>
  <c:when test="${epBlockEditForm.map.isPortletBlock == false}">
            <html-el:text property="name" size="30" maxlength="80"/> 
  </c:when>
  <c:otherwise>
            <html-el:hidden property="name"/>
            <c:out value="${epBlockEditForm.map.name}"/>
  </c:otherwise>
</c:choose> 
          </td>
        </tr>
        <tr> 
          <td class="label" width="30%">
            <bean-el:message key="ep.block.display.template" bundle="ep.messages"/>:*
          </td>
          <td class="labelField" width="70%">
<c:choose>
  <c:when test="${epBlockEditForm.map.displayTemplateIdList == null}">
            <html-el:hidden property="displayTemplateId"/>
  </c:when>
  <c:otherwise>
            <html-el:select property="displayTemplateId" size="1">
              <html-el:optionsCollection property="displayTemplateIdList"/>
            </html-el:select>
  </c:otherwise>
</c:choose>
          </td>
        </tr>
        <tr> 
          <td class="label" width="30%">
            <bean-el:message key="ep.block.description" bundle="ep.messages"/>:
          </td>
          <td class="labelField" width="70%">
            <html-el:textarea property="description" rows="4" cols="50"/>
          </td>
        </tr>
        <tr> 
          <td class="label" width="30%">
            <bean-el:message key="ep.block.type" bundle="ep.messages"/>:
          </td>
          <td class="labelField" width="70%">
<c:choose>
  <c:when test="${epBlockEditForm.map.isSearchBlock == false && epBlockEditForm.map.isNavigationBlock == false}">
            <html-el:radio property="blockType" value="2"/>
            <bean-el:message key="ep.block.type.required" bundle="ep.messages"/>
            &nbsp;
            <html-el:radio property="blockType" value="1"/>
            <bean-el:message key="ep.block.type.default" bundle="ep.messages"/>
            &nbsp;
            <html-el:radio property="blockType" value="0"/>
            <bean-el:message key="ep.block.type.optional" bundle="ep.messages"/>
  </c:when>
  <c:otherwise>
            <html-el:hidden property="blockType"/>
    <c:if test="${epBlockEditForm.map.isSearchBlock == true}">
            <bean-el:message key="ep.block.type.search" bundle="ep.messages"/>
    </c:if>
    <c:if test="${epBlockEditForm.map.isNavigationBlock == true}">
            <bean-el:message key="ep.block.type.navigation" bundle="ep.messages"/>
    </c:if>
  </c:otherwise>
</c:choose> 
          </td>
        </tr>
<c:if test="${epBlockEditForm.map.isPortletBlock == true}">
        <tr> 
          <td class="label" width="30%">
            <bean-el:message key="ep.block.portlet.entity.name" bundle="ep.messages"/>:
          </td>
          <td class="labelField" width="70%">
            <c:out value="${epBlockEditForm.map.portletEntityName}"/>
          </td>
        </tr>
        <tr> 
          <td class="label" width="30%">
            <bean-el:message key="ep.block.portlet.entity.status" bundle="ep.messages"/>:
          </td>
          <td class="labelField" width="70%">
            <c:choose>
              <c:when test="${epBlockEditForm.map.portletEntityStatus == 0}">
                <bean-el:message key="ep.label.offline" bundle="ep.messages"/>
              </c:when>
	            <c:otherwise>
	              <bean-el:message key="ep.label.online" bundle="ep.messages"/>
	            </c:otherwise>
            </c:choose>
          </td>
        </tr>
</c:if>
      </table>
      <div class="pageButtonWrap" align="right">
        <input type="button" name="actionReset" class="pageButton" 
          onclick="doResetAction(this.form);"
          value='<bean-el:message key="button.reset" bundle="ep.messages"/>'>
        &nbsp;&nbsp;
        <input type="button" name="actionCancel" class="pageButton" 
          onclick="doCancelAction(this.form);"
          value='<bean-el:message key="button.cancel" bundle="ep.messages"/>'>
        <input type="submit" name="actionSaveContinue" class="pageButton"
          value='<bean-el:message key="button.save" bundle="ep.messages"/>'>
      </div>
    </td> 
  </tr>
</table>
</html-el:form> 
